﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FileProcessor.Filter;

namespace FileProcessor
{
	public static class Processor
	{
		private static List<SubSet> fileSets=new List<SubSet>();

		public static void CreateSet(string cmd)
		{
			fileSets.Add(SSParser.SetCreaterExec(cmd));
			Console.WriteLine("New Set Created:"+ (fileSets.Count - 1));
		}

		public static void SetCount()
		{
			Console.WriteLine("total set:"+fileSets.Count);
		}

		public static void ViewSet(int id)
		{
			Console.WriteLine(fileSets[id]);
		}

		public static void SetFolder(int id,string url)
		{
			fileSets[id].url = url;
		}

		public static void SizeOfSet(int id)
		{
			Console.WriteLine("Size of "+id.ToString()+" is:"+ fileSets[id].Count);
		}

		public static void MapFunctionHelp()
		{
			Console.WriteLine("copy; copy the data from a set to another set ==");
			Console.WriteLine("rdpi; vague the image from a set to another set with 0.6 ==");
			Console.WriteLine("rname; rename the data from a set to another set ==");
		}
		public static void Map(int id1, int id2,string func)
		{
			if (fileSets[id1].url=="")
			{
				Console.WriteLine("first set url not set");
				return;
			}
			if (fileSets[id2].url == "")
			{
				Console.WriteLine("second set url not set");
				return;
			}
			FilterFather ff=new FilterFather();
			switch(func)
			{
				case "copy":
					ff = new CopyFilter();
					break;
				case "rdpi":
					ff = new ReduceDPIFIlter();
					break;
				case "rname":
					ff = new RNameFilter();
					break;
			}
			try
			{
				if (fileSets[id1].Count == fileSets[id2].Count)
				{
					for (int i = 0; i < fileSets[id1].Count; i++)
					{
						ff.Process(fileSets[id1].url + fileSets[id1].Get(i), fileSets[id2].url + fileSets[id2].Get(i));
					}
					Console.WriteLine("Process Done!");
					return;
				}
				if (fileSets[id1].Count > fileSets[id2].Count && fileSets[id2].Count == 1)
				{
					for (int i = 0; i < fileSets[id1].Count; i++)
					{
						ff.Process(fileSets[id1].url + fileSets[id1].Get(i), fileSets[id2].url + fileSets[id2].Get(0));
					}
					Console.WriteLine("Process Done!");
					return;
				}
				if (fileSets[id1].Count < fileSets[id2].Count && fileSets[id1].Count == 1)
				{
					for (int i = 0; i < fileSets[id2].Count; i++)
					{
						ff.Process(fileSets[id1].url + fileSets[id1].Get(0), fileSets[id2].url + fileSets[id2].Get(i));
					}
					Console.WriteLine("Process Done!");
					return;
				}
			}
			catch (System.Exception ex)
			{
				Console.WriteLine("Condition no fitted, no job done!");
				return;
			}
			Console.WriteLine("Condition no fitted, no job done!");
		}
	}
}
